<?php
    use User\Model\LotteryModel;
?>
<style>
    .table>thead>tr>th{text-align: center}
    .table>tbody>tr>td{vertical-align: middle;text-align: center}
    .table>tbody>tr>td>a{margin-top:5px}
    .btn-custom{color:white} .btn-custom:hover{color:white}
    .color1{background-color:#199ED8} .color2{background-color:#999933} .color3{background-color:#5CB85C}
    .color4{background-color:#F0AD4E} .color5{background-color:#D9534F} .color6{background-color:#FFCC33}
    .color7{background-color:#FF66CC} .color8{background-color:#66CCFF} .color9{background-color:#660000}
</style>
<div class="page-heading">
    <h3>{$lottery["title"]} - 获奖名单</h3>
</div>
<div class="row">
    <div class="col-lg-12">
        <div class="panel">
            <div class="panel-heading">
                <form class="input-group" action="/User/Lottery/awardList" style="width:100%;margin-left:15px">
                    <input type="hidden" name="id" value="{$id}">
                    <span class="input-group-btn" style="width:50px;float:right">
                        <button class="btn btn-default" type="submit">
                            <i class="fa fa-search"></i>
                        </button>
                    </span>
                    <input type="text" class="form-control" style="width:250px;float:right" name="query" placeholder="姓名或联系方式" value="{$query}">
                </form>
            </div>
            <div class="panel-body">
                <div class="col-lg-12">
                    <div class="table-responsive">
                        <button type="button" onclick="return download();" class="btn btn-info">导出</button>
                        <table class="table table-bordered">
                            <thead>
                            <tr>
                                <th>编号</th>
                                <th>姓名</th>
                                <th>联系方式</th>
                                <th width="15%">地址</th>
                                <th>奖项等级</th>
                                <th>奖项名称</th>
                                <th>中奖时间</th>
                                <th>奖品状态</th>
                                <th>操作</th>
                            </tr>
                            </thead>
                            <tbody>
                            <volist name="list" id="item">
                                <tr>
                                    <td>{$item.id}</td>
                                    <td>{$item.name}</td>
                                    <td>{$item.phone}</td>
                                    <td><span style="word-break:break-all;word-wrap:break-word">{$item.address}</span></td>
                                    <td>{$item.level_name}</td>
                                    <td>{$item.award_name}</td>
                                    <td>{$item.createdate}</td>
                                    <td>
                                        <if condition="$item.status eq LotteryModel::AWARD_CHECKED">
                                            <span class="label color3">已核销</span>
                                        <else/>
                                            <span class="label color6">未核销</span>
                                        </if>
                                    </td>
                                    <td>
                                        <if condition="$item.status eq LotteryModel::AWARD_ACTIVE">
                                            <a type="button" href="javascript:;" onclick="return statusLottery({$item['id']}, 'check');" class="btn btn-custom color3">核销</a>
                                        </if>
                                        <a type="button" href="javascript:;" onclick="return statusLottery({$item['id']}, 'delete');" class="btn btn-custom color5">删除</a>
                                    </td>
                                </tr>
                            </volist>
                            </tbody>
                        </table>
                    </div>
                    <div class="pages">
                        {$page}
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<script>
    function statusLottery(id, status){
        console.log(id);
        console.log(status);
        if(status === "check"){
            if(!confirm('确认核销吗？')) return false;
        }else{
            if(!confirm('确认删除吗？')) return false;
        }
        $.ajax({
            data: {id: id, status: status},
            dataType: 'json',
            url: '/User/Lottery/statusAward',
            type: 'get',
            success: function (res) {
                alert(res['info']);
                window.location.reload();
            }
        });
        return false;
    }
    function download(){
        var id = $("input[name=id]").val();
        var query = $("input[name=query]").val();
        window.location = "/User/Niudan/exportAwards?id="+id+"&query="+query;
        return false;
    }
</script>